#include <bits/stdc++.h>
#define int long long
using namespace std;

inline int read() {
	int x = 0, f = 0; char ch = getchar();
	while (ch < '0' or ch > '9') f |= (ch == '-'), ch = getchar();
	while (ch >= '0' and ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

int __stk[128], __top;
inline void write(int x) {
    if(x < 0) putchar('-'), x = -x;
	do { __stk[++__top] = x % 10, x /= 10; } while (x);
	while (__top) putchar(__stk[__top--] + '0');
}

const int mod = 998244353;

void Min(int &x, int y) { y < x and (x = y); }
void Max(int &x, int y) { y > x and (x = y); }

void inc(int &x, int y) { (x += y) >= mod and (x -= mod); }
void mul(int &x, int y) { x = 1ll * x * y % mod; }

int q_pow(int x, int k) { int res = 1; for (; k; k >>= 1, mul(x, x)) if (k & 1) mul(res, x); return res; }

bool stmer;

const int N = 5e5 + 10;

int n, q, p;
int s[N], to[N];

int f(int a, int b) {
    int res = 0;
    for (int i = 0; i < p; i++) to[i] = (1ll * i * a + b) % p;
    for (int l = 1; l <= n; l++) for (int r = l; r <= n; r++) {
        bool flag = 1; int mid = (l + r) >> 1;
        for (int i = l; i <= mid and flag; i++)
            flag &= to[s[i]] == s[l + r - i], flag &= to[s[l + r - i]] == s[i];
        res += flag;
    }
    return res;
}

bool edmer;
signed main() {
	freopen("string.in", "r", stdin);
	freopen("string.out", "w", stdout);
	cerr << "[Memory] " << (&stmer - &edmer) / 1024 / 1024 << " MB\n";
	
    n = read(), q = read(), p = read();
    for (int i = 1; i <= n; i++) s[i] = read();

    while (q--) {
        int op = read(), x = read(), ans = 0;
        for (int i = 0; i < p; i++) ans += op == 1 ? f(x, i) : f(i, x);
        write(ans), putchar('\n');
    }

    cerr << "[Runtime] " << (double) clock() / CLOCKS_PER_SEC << " seconds\n";
	return 0;
} 